package b3.widget.basic
{
	import b3.util.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	import flash.filters.*;
	import flash.ui.Mouse;

	public class ImgSwitchIcon extends Sprite
	{
		private var backgroundImage:Sprite; 
		private var mouseOverImage:Sprite;
		
		public function ImgSwitchIcon(BackgroundImage:Class, MouseOverImage:Class, tipText:String = null, tipPosType:int = 0, textEmbeddedFlag:Boolean = false)
		{
			super();
			backgroundImage = new BackgroundImage();
			backgroundImage.mouseChildren = false;
			addChild(backgroundImage);
			mouseOverImage = new MouseOverImage();
			mouseOverImage.mouseChildren = false;
			mouseOverImage.visible = false;
			addChild(mouseOverImage);
			//文字嵌入到图片下部
			if (tipText != null && textEmbeddedFlag)
			{
				var embeddedText:TextField = new TextField();
				embeddedText.selectable = false;
	        	embeddedText.autoSize = TextFieldAutoSize.CENTER;
	        	if (tipText.length < 5)
					embeddedText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x0088FF);
				else
	        		embeddedText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x0088FF);
				embeddedText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
				embeddedText.text = tipText;
				embeddedText.x = (backgroundImage.width - embeddedText.width) / 2;
				if (tipPosType == 0)
					embeddedText.y = -embeddedText.height;
				else
					embeddedText.y = backgroundImage.height - 5;
				addChild(embeddedText);
			}
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			backgroundImage.visible = false;
			mouseOverImage.visible = true;
			Mouse.cursor = "button";
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			backgroundImage.visible = true;
			mouseOverImage.visible = false;
			Mouse.cursor = "auto";
		}
	}
}